//
//  ComponentSelectController.m
//  costa-postcards
//
//  Created by 黄 鹏霄 on 12-12-14.
//  Copyright (c) 2012年 test. All rights reserved.
//

#import "ComponentSelectController.h"

@interface ComponentSelectController ()

@end

@implementation ComponentSelectController
@synthesize table = _table;
@synthesize delegate = _delegate;

- (void)loadView
{
//    [super loadView];
    [self setTable:[[UITableView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame] style:UITableViewStyleGrouped]];
    [self table].delegate = self;
    [self table].dataSource = self;
    
    self.view = self.table;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"cancel" style:UIBarButtonItemStyleBordered target:self action:@selector(cancel:)];

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - cancel
- (void)cancel:(UIButton *)sender
{
    [self dismissModalViewControllerAnimated:YES];
}

#pragma mark - data source 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier];
    }
    cell.textLabel.text = @"select a photo from library";
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    return cell;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

#pragma mark - delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    UIImagePickerController *controller = [[UIImagePickerController alloc]init];
    controller.delegate = self;
    controller.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    [self.navigationController presentModalViewController:controller animated:NO];
    [controller release];
    
}

#pragma mark - image picker delegate
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo 
{
    NSLog(@"%@",image);
    
    [picker dismissModalViewControllerAnimated:NO];
    [[self delegate] modalViewWillDisappear:self selectedImage:image];
}




@end
